<template>
	<view class="page" v-if="loadding" :style="{minHeight:windowHeight+'px'}">
		<view class="item">
			<view class="item-con" v-for=" (item,index) of listData" :key="index">
				<!-- <view class="item-con-time">3-12 09:30</view> -->
				<view class="item-con-content">
					<view class="item-con-content-title">
						<view>订单通知</view>
					</view>
					<view class="item-con-content-info">
						{{item.content}}
					</view>
					<view class="item-con-content-time">
						{{item.thumb}}
					</view>
				</view>
			</view>
			<!-- <view class="item-con" v-for=" n of 3"  >
				<view class="item-con-time">3-12 09:30</view>
				<view class="item-con-content">
					<view class="item-con-content-title">
						<view>订单通知</view>
						<image src="../../../static/jiantou3.png"></image>
					</view>
					<view class="item-con-content-info">
						<text>您的订单：</text>
						<view>16859996666</view><text>已经下单成功!</text>
					</view>
					<view class="item-con-content-time">
						2020-5-12
					</view>
				</view>
			</view> -->
			<view style="height: 40rpx;"></view>
		</view>
		<view class="null d-c-c p30" v-if="listData.length == 0">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<view v-else v-show="isLoadMore">
			<uni-load-more :loadingType="loadding2"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				loadding:false,
				windowHeight: '',
				listData:[],
				oadStatus: 'loading',
				isLoadMore: false, //是否加载中
				page: 1,
				pagesize: 10,
				loadding2: 0,
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight
				}
			})
		},
		onShow() {
			this.getInfo();
		},
		onPullDownRefresh() {
			this.page = 1;
			this.listData2 = [];
			this.getInfo();
			setTimeout( () => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.page += 1
				this.getInfo();
			}
		},
		methods: {
			/* 获取消息 */
			getInfo() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._post('user.index/order_message', {
						page: self.page,
						pageSize:self.pagesize
					},
					function(res) {
						
						//self.listData2 = res.data.list.data;
						if (res.data.list.data) {
							self.listData = self.listData.concat(res.data.list.data)
							self.listData.forEach(item => {
								var date = new Date(item.create_time * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
								var Y = date.getFullYear() + '-';
								var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
								var D = date.getDate() + ' ';
								var h = date.getHours() + ':';
								var m = date.getMinutes() + ':';
								var s = date.getSeconds();
								//console.log(Y+M+D+h+m+s)
								item.thumb = Y+M+D+h+m+s
							})
							if (res.data.list.data.length < res.data.list.per_page) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
								self.isLoadMore = true
								self.loadding2 = 2
							} else {
								self.isLoadMore = false
							}
						} else {
							self.isLoadMore = true
							self.loadding2 = 2
						}
						self.loadding = true;
						uni.hideLoading();
					});
			},
		}
	}
</script>

<style>
	.page {
		width: 100%;
		background-color: #FCFBFF;
		overflow: hidden;
	}

	.item {
		width: 100%;
		margin-top: 10rpx;
		//margin-bottom: 130rpx;
	}

	.item-con {
		width: 96%;

		margin: 40rpx auto 0;
		//background-color: #FFFFFF;				
	}

	.item-con-time {
		margin-bottom: 40rpx;
		font-size: 28rpx;
		text-align: center;
	}

	.item-con-content {
		background-color: #FFFFFF;
		padding: 30rpx;
		box-shadow: 0 0 30rpx 2rpx #dfd9cf;
	}

	.item-con-content-title {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.item-con-content-title view {
		font-size: 30rpx;
		font-weight: 800;
	}

	.item-con-content-title image {
		width: 46rpx;
		height: 46rpx;
	}

	.item-con-content-info {
		display: flex;
		align-items: center;
		margin: 10rpx 0;
		font-size: 26rpx;
	}

	.item-con-content-time {
		color: #999999;
	}
	.null{
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0rpx;
		background-color: #F4F4F4;
		z-index: 99;
	}
</style>
